/*评论接口*/
import { Message } from 'element-ui'
import { pubRequire } from '@utils/public'
import { getRandomRobotId } from '@utils/dictionariesFunc'
const baseUrl = '/comments'
/*随机马甲-添加评论*/
export async function addRobotCommon(obj) {
  return new Promise((resolve, reject) => {
    let url = `${baseUrl}`
    pubRequire(
      'post',
      url,
      obj,
      (response) => {
        resolve(true)
      },
      (response) => {
        Message.warning(response.message)
        resolve(false)
      }
    )
  })
}
/*评论列表-常规位
obj = {
      topicType,//话题类型
      topicId,//话题id
      pageSize,//页大小
      pageNum//页码
    }
 * */
export function getBase(obj) {
  return new Promise((resolve, reject) => {
    let url = `${baseUrl}/base`
    pubRequire('get', url, obj, (response) => {
      resolve(response)
    })
  })
}
/*评论列表-推荐位
obj = {
      topicType,//话题类型
      topicId,//话题id
      pageSize,//页大小
      pageNum//页码
    }
 * */
export function getRecommend(obj) {
  return new Promise((resolve, reject) => {
    let url = `${baseUrl}/recommend`
    pubRequire('get', url, obj, (response) => {
      resolve(response)
    })
  })
}
/*置顶*/
export function recommend(commentId) {
  return new Promise((resolve, reject) => {
    let url = `${baseUrl}/${commentId}/top`
    pubRequire(
      'put',
      url,
      '',
      (response) => {
        Message.success('置顶成功')
        resolve(true)
      },
      (response) => {
        Message.warning(response.message)
      }
    )
  })
}
/*取消置顶*/
export function cRecommend(commentId) {
  return new Promise((resolve, reject) => {
    let url = `${baseUrl}/${commentId}/untop`
    pubRequire(
      'put',
      url,
      '',
      (response) => {
        Message.success('取消置顶成功')
        resolve(true)
      },
      (response) => {
        Message.warning(response.message)
      }
    )
  })
}
/*回复列表
 *commentId - 评论id
 *obj = {
      pageSize,//页大小
      pageNum//页码
    }
 * */
export function getReplys(commentId, obj) {
  return new Promise((resolve, reject) => {
    let url = `${baseUrl}/${commentId}/replys`
    pubRequire('get', url, obj, (response) => {
      resolve(response)
    })
  })
}
//获取列表
export function pubReply(commentId, params, callBack, errBack) {
  return pubRequire(
    'post',
    `${baseUrl}/${commentId}/replys`,
    params,
    callBack,
    errBack
  )
}
//获取历史消息列表
export function getHistoryList(commentId, callBack, errBack) {
  return pubRequire(
    'get',
    `${baseUrl}/${commentId}/history`,
    '',
    callBack,
    errBack
  )
}
